﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FactoryDeviceSystem.Utils
{
    public class DrawUtil
    {
        public static GraphicsPath GetRoundPath(Rectangle rect, float radius)
        {
            float d = 2 * radius;

            if(d > rect.Height)
            {
                d = rect.Height;
            }

            GraphicsPath path = new GraphicsPath();
            // 左上 上 右上 右 右下 下 左下 左 
            path.AddArc(rect.X, rect.Y, d, d, 180f, 90f);
            path.AddLine(rect.X + radius, rect.Y, rect.Right - d,rect.Y);

            path.AddArc(rect.Right - d, rect.Y, d, d, 270f, 90f);
            path.AddLine(rect.Right, rect.Y + radius, rect.Right, rect.Bottom - radius);

            path.AddArc(rect.Right - d, rect.Bottom - d, d, d, 0f, 90f);
            path.AddLine(rect.Right - radius, rect.Bottom, rect.X + radius, rect.Bottom);

            path.AddArc(rect.X, rect.Bottom - d, d, d, 90f, 90f);
            path.AddLine(rect.X,rect.Bottom - radius,rect.X,rect.Y + radius);

            return path;
        }
    }
}
